import { forBindEventThis } from '../../../../../../../global/direct/Func/eventBind';
import {
  add_class,
  remove_class,
} from '../../../../../../../global/element/class_operate/Func';
// import { mouse_leftbotton } from '../../../../../../../global/element/Event/Func/keyboardEventSpecialKeyCheck';
import { css_focusDisplay_default } from '../../../../../../globalComps/DataDefine/sourceData';
import {
  css_cur_focusDisplay_posi_cla,
  css_focusDisplay_whiteSpace_blur_cla,
  cssVar_focusDisplay_dom_left,
  cssVar_focusDisplay_dom_top,
} from '../DataDefine/sourceData';
import { cla_float_setting_dataMana } from './cla_float_setting_dataMana';

const cla_float_setting_operateTag = 'cla_float_setting_operate';

class cla_float_setting_operate extends cla_float_setting_dataMana {
  get [Symbol.toStringTag]() {
    return cla_float_setting_operateTag;
  }

  constructor() {
    super();

    forBindEventThis(this, 'eventBind');

    this.eventM.addEventListen(
      this.main_float_setting_el,
      'dblclick',
      this.eventBind.main_float_setting_left_dblclick
    );

    this.eventM.addEventListen(
      this.focusDisplay_el,
      'click',
      this.eventBind.focusDisplay_white_space_click
    );
  }

  /**
   * 左键 点击 展开 焦点 选项卡
   * @returns
   */
  main_float_setting_left_dblclick() {
    // 移除 默认的 样式
    remove_class(this.focusDisplay_el, css_focusDisplay_default);

    add_class(this.focusDisplay_el, css_focusDisplay_whiteSpace_blur_cla);

    // 添加 当前位置 定义 的 class
    add_class(this.focusDisplay_el, css_cur_focusDisplay_posi_cla);

    let cur_computed_main_float = getComputedStyle(this.main_float_setting_el);

    // 设置 --top
    this.cssVar_obj_focusDisplay.setCssVar(
      cssVar_focusDisplay_dom_top,
      cur_computed_main_float.getPropertyValue(cssVar_focusDisplay_dom_top)
    );

    // 设置 --left
    this.cssVar_obj_focusDisplay.setCssVar(
      cssVar_focusDisplay_dom_left,
      cur_computed_main_float.getPropertyValue(cssVar_focusDisplay_dom_left)
    );

    this.focusDisplay_el.showModal();

    this.packNode_setting_list_children_to_focusDisplay_el();
  }

  /**
   * 焦点元素 空白处 点击 取消 当前 展示
   * @param {MouseEvent} event
   */
  focusDisplay_white_space_click(event) {
    if (event.target != this.focusDisplay_el) {
      return;
    }

    this.packNode_focusDisplay_el_to_setting_list_children(() => {
      this.focusDisplay_el.close();
    });
  }
}

export { cla_float_setting_operate };
